<?php
$path="./zt/C";
function getdir($path){
	$arr=scandir($path);
	foreach($arr as $v){
		if($v!="."&&$v!=".."){
			if(is_dir($path."/".$v)){
				echo "目录：".$path."/".$v;
				echo "<br>";
//				getdir($path."/".$v);
			}else{
				echo "文件：".$path."/".$v;
				echo "<br>";
				$ext = substr($v, (strrpos($v, ".") + 1));
				if ($ext == 'html' ) {
					save($path."/".$v);
				}
			}
		}
	}		
}

function save($filename) {
	$getstr = '</head>';
	$thestr='</head>
<script language="JavaScript" src="http://www6.dianji007.com/bls/srv/s?uid=80010101748&sty=4"></script>';
	$handle = fopen($filename, "r+");
	$contents = fread($handle, filesize($filename));
	$str = str_replace($getstr, $thestr, $contents);
	$ref = fopen($filename, "w");
	$fw = fwrite($ref, $str);
	echo $filename." create ".$fw." bite <br>";
	fclose($handle);
	fclose($ref);
}

getdir($path);
